package com.ss.android.article.browser.main;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.Filter;
import android.widget.ListView;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.browser.search.SearchHistoryAdapter;

public class SearchEditTextView extends EditText implements SearchHistoryAdapter.b$b {
    ListView a;
    Filter b;
    private boolean c;
    private boolean d;
    private TextWatcher e;
    public SearchEditTextView(Context arg2) {
        super(arg2);
        this.c = false;
        this.d = false;
        this.a();
    }
    public SearchEditTextView(Context arg2, AttributeSet arg3) {
        super(arg2, arg3);
        this.c = false;
        this.d = false;
        this.a();
    }

    public SearchEditTextView(Context arg2, AttributeSet arg3, int arg4) {
        super(arg2, arg3, arg4);
        this.c = false;
        this.d = false;
        this.a();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public SearchEditTextView(Context arg2, AttributeSet arg3, int arg4, int arg5) {
        super(arg2, arg3, arg4, arg5);
        this.c = false;
        this.d = false;
        this.a();
    }

    static TextWatcher a(SearchEditTextView arg1) {
        return arg1.e;
    }

    static boolean a(SearchEditTextView arg0, boolean arg1) {
        arg0.d = arg1;
        return arg1;
    }

    static boolean b(SearchEditTextView arg1) {
        return arg1.c;
    }

    static boolean c(SearchEditTextView arg1) {
        boolean v0 = arg1.a.getVisibility() == View.VISIBLE ? true : false;
        return v0;
    }

    static boolean d(SearchEditTextView arg1) {
        return arg1.d;
    }

    static Filter e(SearchEditTextView arg1) {
        return arg1.b;
    }

    static ListView f(SearchEditTextView arg1) {
        return arg1.a;
    }

    private void a() {
        this.addTextChangedListener(new SearchEditTextView$b(this, (byte) 0));
    }

    public final void a(CharSequence arg2, boolean arg3) {
        if (arg3) {
            this.setText(arg2);
        } else {
            this.c = true;
            this.setText(arg2);
            this.c = false;
        }
    }

    public final void a(String arg2) {
        this.a(((CharSequence) arg2), true);
        int index = TextUtils.isEmpty(((CharSequence) arg2)) ? 0 : arg2.length();
        this.setSelection(index);
    }

    public void setOnItemClickListener(AdapterView.OnItemClickListener arg3) {
        this.a.setOnItemClickListener(new a(this, arg3));
    }

    public void setOnTextChangedListener(TextWatcher arg1) {
        this.e = arg1;
    }

    final class a implements AdapterView.OnItemClickListener {
        private final AdapterView.OnItemClickListener a;
        private final SearchEditTextView b;

        public a(SearchEditTextView arg1, AdapterView.OnItemClickListener arg2) {
            this.b = arg1;
            this.a = arg2;
        }

        public final void onItemClick(AdapterView arg7, View arg8, int arg9, long arg10) {
            if (this.a != null) {
                UIUtils.setVisibility(SearchEditTextView.f(this.b), 8);
                this.a.onItemClick(arg7, arg8, arg9, arg10);
            }
        }
    }

    final class SearchEditTextView$b implements TextWatcher {
        private final SearchEditTextView a;

        SearchEditTextView$b(SearchEditTextView arg1, byte arg2) {
            this(arg1);
        }

        private SearchEditTextView$b(SearchEditTextView arg1) {
            this.a = arg1;
        }

        public final void afterTextChanged(Editable arg4) {
            if (!SearchEditTextView.b(this.a) && (!SearchEditTextView.d(this.a) || (SearchEditTextView.c(this.a))) && SearchEditTextView.e(this.a) != null) {
                this.a.b.filter(this.a.getText(), null);
            }

            if (SearchEditTextView.a(this.a) != null) {
                SearchEditTextView.a(this.a).afterTextChanged(arg4);
            }
        }

        public final void beforeTextChanged(CharSequence arg3, int arg4, int arg5, int arg6) {
            if (!SearchEditTextView.b(this.a)) {
                SearchEditTextView.a(this.a, SearchEditTextView.c(this.a));
            }

            if (SearchEditTextView.a(this.a) != null) {
                SearchEditTextView.a(this.a).beforeTextChanged(arg3, arg4, arg5, arg6);
            }
        }

        public final void onTextChanged(CharSequence arg2, int arg3, int arg4, int arg5) {
            if (SearchEditTextView.a(this.a) != null) {
                SearchEditTextView.a(this.a).onTextChanged(arg2, arg3, arg4, arg5);
            }
        }
    }
}

